﻿namespace Algo
{
    using System;
    using System.Collections.Generic;
    using System.Diagnostics.Contracts;

    using JetBrains.Annotations;

    public static class SortExtensions
    {
        [NotNull] public static IEnumerable<T> Sort<T>([NotNull] this ISortStrategy sortingStrategy, [NotNull] IEnumerable<T> items, [NotNull] IComparer<T> comparer)
        {
            Contract.Requires<ArgumentNullException>(sortingStrategy != null);
            Contract.Requires<ArgumentNullException>(items != null);
            Contract.Requires<ArgumentNullException>(comparer != null);
            Contract.Ensures(Contract.Result<IEnumerable<T>>() != null);

            return sortingStrategy.Sort(items, comparer, EmptyExtensions.Instance);
        }

        [NotNull] public static IEnumerable<T> Sort<T>([NotNull] this ISortStrategy sortingStrategy, [NotNull] IEnumerable<T> items, [NotNull] IAlgoExtensions extensions)
        {
            Contract.Requires<ArgumentNullException>(sortingStrategy != null);
            Contract.Requires<ArgumentNullException>(items != null);
            Contract.Requires<ArgumentNullException>(extensions != null);
            Contract.Ensures(Contract.Result<IEnumerable<T>>() != null);

            return sortingStrategy.Sort(items, Comparer<T>.Default, extensions);
        }

        [NotNull] public static IEnumerable<T> Sort<T>([NotNull] this ISortStrategy sortingStrategy, [NotNull] IEnumerable<T> items)
        {
            Contract.Requires<ArgumentNullException>(sortingStrategy != null);
            Contract.Requires<ArgumentNullException>(items != null);
            Contract.Ensures(Contract.Result<IEnumerable<T>>() != null);

            return sortingStrategy.Sort(items, Comparer<T>.Default, EmptyExtensions.Instance);
        }
    }
}